namespace Maple.Branch.Features.FeatureProviders
{
    using IServices;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Features;
    using Volo.Abp.MultiTenancy;

    public class TenantFeatureProvider : BranchFeatureProvider, ITransientDependency
    {
        public override string Name => TenantFeatureValueProvider.ProviderName;

        protected ICurrentTenant CurrentTenant { get; }

        public TenantFeatureProvider(
            IBranchFeatureStore store,
            ICurrentTenant currentTenant)
            : base(store)
        {
            CurrentTenant = currentTenant;
        }

        protected override string NormalizeProviderKey(string providerKey)
        {
            if (providerKey != null)
            {
                return providerKey;
            }

            return CurrentTenant.Id?.ToString();
        }
    }
}
